import { h } from "vue";
import ImageUpload from "@/components/Crud/form/ImageUpload.vue";
import ImagesUpload from "@/components/Crud/form/ImagesUpload.vue";
import FileUpload from "@/components/Crud/form/FileUpload.vue";
import DynamicSelect from "@/components/Crud/form/DynamicSelect.vue";

export const functions = {
  /**
   * 图片上传
   * @param value
   * @param onChange
   * @param props
   */
  imageUpload: function (value, onChange, props) {
    return h(ImageUpload, {
      value: value,
      props: props,
      "onUpdateImageUrl-event": (value: any) => {
        onChange(value);
      }
    });
  },
  /**
   * 多图片上传
   * @param value
   * @param onChange
   * @param props
   */
  imagesUpload: function (value, onChange, props) {
    return h(ImagesUpload, {
      props: props,
      value: value,
      "onUpdateImageUrl-event": (value: any) => {
        onChange(value);
      }
    });
  },
  /**
   * 单文件上传
   * @param value
   * @param onChange
   * @param props
   */
  fileUpload: function (value, onChange, props) {
    return h(FileUpload, {
      props: props,
      value: value,
      limit: 1,
      "onUpdateFileUrl-event": (value: any[]) => {
        onChange(value[0].url);
      }
    });
  },
  /**
   * 多文件上传
   * @param value
   * @param onChange
   * @param props
   */
  filesUpload: function (value, onChange, props) {
    return h(FileUpload, {
      props: props,
      fileUrl: value,
      limit: 50,
      "onUpdateFileUrl-event": (value: any) => {
        onChange(value);
      }
    });
  },
  dynamicSelect: function (value, onChange, props, item) {
    return h(DynamicSelect, {
      props: props,
      value: value,
      item: item,
      "onUpdateValue-event": (value: any) => {
        onChange(value);
      }
    });
  }
};
